package week02;

import java.io.FileInputStream;
import java.io.IOException;
import java.util.Properties;

public class AuthenticatorFactory {

    private static Properties prop = new Properties();

    static {
        try {
            prop.load(new FileInputStream("src/week02/auth.properties"));
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    public static Authenticator createAuthenticator() {
             KeyValueKeeper keeper=createKeyValueKeeper();
             Encrypter encrypter=createEncrypter();
             return new Authenticator(keeper,encrypter);
    }



    private static KeyValueKeeper createKeyValueKeeper() {
        MemoryKeeper keyv=null;
        try{
            keyv=(MemoryKeeper) Class.forName(prop.getProperty("KeyValueKeeper")).newInstance();
        }catch (Exception e){
            e.printStackTrace();
        }
        return keyv;
    }

    private static Encrypter createEncrypter() {
        Md5Encrypter enc=null;
        try{
            enc=(Md5Encrypter) Class.forName(prop.getProperty("Encname")).newInstance();
        }catch (Exception e){
            e.printStackTrace();
        }
         return enc;
    }
}
